package com.sqm.conntroller;

import cn.hutool.core.util.StrUtil;

import com.sqm.entity.Result;
import com.sqm.entity.dto.UserDTO;
import com.sqm.entity.vo.UserVO;
import com.sqm.service.UserService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 功能: 登录相关接口
 * 作者: 沙琪马
 * 日期: 2024/5/21 16:45
 */
@RestController
@Slf4j
@RequiredArgsConstructor
    public class WebController {

    private final UserService userService;

    @PostMapping("/login")
    public Result Login(@RequestBody UserDTO userDTO){
        log.info("用户{}登录", userDTO.getUsername());
        if(StrUtil.isBlank(userDTO.getUsername()) || StrUtil.isBlank(userDTO.getPassword())){
            throw new RuntimeException("用户名或密码不能为空");
        }
        UserVO user = userService.login(userDTO);

        return Result.success(user);
    }

}
